// const webpack = require('webpack');
const path = require('path');
// const VersionPlugin = require('./src/plugins/version-plugin');
// var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
function resolve (dir) {
  return path.join(__dirname, './', dir);
}
var _src = resolve('src');
// 插件添加
const configPlugins = [];
if (process.env.NODE_ENV === 'production') {
  // 添加版本号
  // configPlugins.push(new VersionPlugin({ buildPath: resolve('build/mall_build'), rootPath: resolve('/'), versionDirectory: 'static' }));
  // 添加打包性能检查
  // configPlugins.push(new BundleAnalyzerPlugin());
}
module.exports = {
  productionSourceMap: false,
  configureWebpack: {
    plugins: configPlugins
  },
  outputDir: 'build/mall_build',
  assetsDir: 'static',
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('~', resolve('public'));
  },
  filenameHashing: false,
  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          // 或者可以通过 less 文件覆盖（文件路径为绝对路径）
          'hack': `true; @import "${_src}/assets/style/theme.less";`
        }
      },
      postcss: {
        plugins: [
          require('postcss-pxtorem-multi')({
            rootValue: 75,
            propList: ['*'],
          }) // 换算的基数
        ]
      }
    }
  },
  devServer: {
    disableHostCheck: true,
    proxy: {
      '/api': {
        target: process.env.VUE_APP_SERVER_URL, // 服务器接口域名
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
};
